﻿<?php
require('../database/db.php');
$mysql=new mysql();
include("../../tool/UpFileTool.class.php");

// 如果有传入goodsid,且在goods表中有该商品,则执行更新操作
if ($_REQUEST[goodsid]!='') {
	$sql="select * from goods where goodsid=".$_REQUEST[goodsid]. " AND shangjia=1";
	$goods=$mysql->getRow($sql);
	
   $tupian=explode("," ,$goods[images]);//复制图片
   $tupian = array_unique($tupian);
   foreach($tupian as $key=>$v){
	   $yuantu="../".$v;
	   $fuzhi="../../../xzsh/api/".$v;
	   copy("phoneyz.php","T/phoneyz.php");
   }
	   

}else{
	$mode='insert';
	$where = ' where 1 limit 1';
}
// 如果有传入goodsid,且在goods表中有该商品,则执行更新操作 end
//$shopid=trim($goods[shopid]);//商家ID
$name=trim($goods[name]);//商品名称
$shelves=trim($goods[shelves]);//上架
$price=trim($goods[price]);//价格
$images="../../xzpf/".$goods[images];//价格
$original=trim($goods[original]);//原价
$summary=trim($_REQUEST[summary]);//简介
$son_class=trim($_REQUEST[son_class]);//子分类
$guige=trim($_REQUEST[guige]);//规格
$shopid=trim($_REQUEST[userid]);//规格
$guige=explode(';',$guige);
$length=count($guige);


$conn=mysql_connect('localhost','root','') or die('连接失败！'.mysql_error());
mysql_select_db('xzsh',$conn) or die('数据库选择失败:' . mysql_error());
mysql_select_db('db');mysql_query("set names utf8;"); //**设置字符集***
date_default_timezone_set('Asia/Shanghai');
session_start();

$table='goods';
$arr=array(
	'title'=>$name,
	'shangjia'=>$shelves,
	'price'=>$price,
	'yuanjia'=>$original,
	'summary'=>$summary,
	'zixilie'=>$son_class,
	'images'=>$images,
	'srcimages'=>$srcimages,
	'shopid'=>$shopid
);

$mysql->autoExecute($table,$arr,$mode,$where);
if ($mode=='update') {
	$result=$_REQUEST[goodsid];
}else{
	$result=$mysql->insert_id();
}

// 删除之前该商品的规格
//$sql="DELETE from goodsselect where goodsid=".$result;
//$mysql->query($sql);
// 删除之前该商品的规格 end
for($i=0;$i<$length;$i++){

	$ar=explode('-',$guige[$i]);
	$tab='goodsselect';
	$ary=array(
		'goodsid'=>$result,
		'fTitle'=>$ar[0],
		'sTitle'=>$ar[1],
		'price'=>$ar[2],
		'number'=>$ar[3]
	);
	$mysql->autoExecute($tab,$ary);
}
$result2=$mysql->insert_id();


if($result!=false && $result2!=false){
	$der=array('code'=>100);
	
}else{
	$der=array('code'=>200);
}
echo json_encode($der);


?>